package com.huike.controller.clue;

import com.huike.aspect.OperationAnnotation;
import com.huike.dto.ClueDto;
import com.huike.dto.CluePageQueryDto;
import com.huike.dto.FalseClueDto;
import com.huike.entity.Clue;
import com.huike.entity.SysDictData;
import com.huike.result.Result;
import com.huike.service.ClueService;
import com.huike.vo.ClueAssignmentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/clues/clue")
public class ClueController {
    @Autowired
    private ClueService clueService;

    /**
     * 分页
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public Result getClueList(CluePageQueryDto dto) {
        return clueService.getClueList(dto);
    }

    /**
     * 线索池分页
     * @param dto
     * @return
     */
    @GetMapping("/pool")
    public Result getCluePoolList(CluePageQueryDto dto) {
        return clueService.getCluePoolList(dto);
    }

    /**
     * 新增线索
     * @param dto
     * @return
     */
    @OperationAnnotation
    @PostMapping("/create")
    public Result createClue(@RequestBody ClueDto dto) {
        Result clue = clueService.createClue(dto);
        return clue;
    }

    /**
     * 批量分配
     */
    @PutMapping("/assignment")
    public Result assignment(@RequestBody ClueAssignmentVo assignmentVo) {
        return clueService.assign(assignmentVo.getIds(), assignmentVo.getUserName());
    }

    /**
     * 批量捞取
     * @param ids
     * @return
     */
    @PutMapping("/gain")
    public Result gain(@RequestBody Long[] ids) {
        return clueService.gain(ids);
    }

    /**
     * 伪线索上报
     * @return
     */
    @PostMapping("/submit_false")
    public Result submitFalseClue(@RequestBody FalseClueDto dto){
       return clueService.submitFalseClue(dto);
    }

    /**
     * 批量添加
     * @return
     */
    @PostMapping("/upload")
    public Result upload(@RequestParam MultipartFile file) {
        List<Clue> list = clueService.upExcel(file);
        return Result.success("上传成功");
    }

    @GetMapping("/{clueId}")
    public Result getById(@PathVariable Long clueId) {

        return clueService.getById(clueId);
    }


    @GetMapping("/reasons_for_reporting")
    public Result findClueFalseReason(){
        String dictType="reasons_for_reporting";
        List<SysDictData> dictData = clueService.findDictData(dictType);
        return Result.success(dictData);
    }
    @GetMapping("/clues_item")
    public Result findClueReference(){
        String dictType="clues_item";
        List<SysDictData> dictData = clueService.findDictData(dictType);
        return Result.success(dictData);
    }

    @GetMapping("/clue_status")
    public Result findClueStatus(){
        String dictType="clue_status";
        List<SysDictData> dictData = clueService.findDictData(dictType);
        return Result.success(dictData);
    }

    /**
     * 转商机
     * @param clueId
     * @return
     */
    @PutMapping("/changeBusiness")
    public Result changeBusiness(Long clueId){
        clueService.changeBusiness(clueId);
        System.out.println(clueId);
        return Result.success();
    }

}
